
<template>
  <div class="create">
    <div>
      <div :v-if="heroObject.skills" style="display: flex; flex-wrap: wrap">
        <div @click="handleAddSkills" class="addNewReport">+ 新建任务</div>
        <div v-for="(item, index) in ListAllData" :key="index">
          <div class="box_content">
            <div class="box_top">
              <div class="box_top_Icon">
                <img src="../../assets/1.png" v-if="item.img === 1" />
                <img src="../../assets/2.png" v-if="item.img === 2" />
                <img src="../../assets/3.png" v-if="item.img === 3" />
                <img src="../../assets/4.png" v-if="item.img === 4" />
              </div>
              <div class="box_ref_time">
                <div class="box_name">{{ item.name }}</div>
                <div class="box_time">
                  更新时间：{{ item.time }}
                  <Icon type="ios-refresh" class="icons" size="22" />
                </div>
              </div>
            </div>
            <div class="box_foot">
              <div class="bf_btn" @click="settingFactory(item)">设置</div>
              |
              <div class="bf_btn">编辑</div>
              |
              <div class="bf_btn">日志</div>
              |
              <div class="bf_btn">删除</div>

              <!-- <Button
                type="error"
                size="small"
                @click="() => heroObject.skills.splice(index, 1)"
                >删除</Button
              > -->
            </div>
          </div>
        </div>
      </div>
    </div>
    <Modal v-model="modelAdd" title="添加任务" :footer-hide="false">
      <div slot="footer">
        <Button @click="handleCancel">取消</Button>
        <Button type="primary" @click="handleSave">确定</Button>
      </div>
      <Row style="margin-bottom: 20px">
        <Col span="4" style="line-height: 30px">任务图标:</Col>
        <Col span="20" class="Model_add" style="display: flex">
          <div style="margin: 0 5px" @click="imgDefault = 1">
            <div class="zhezhaoceng" v-if="imgDefault === 1"></div>
            <img src="../../assets/1.png" />
          </div>
          <div style="margin: 0 5px" @click="imgDefault = 2">
            <div class="zhezhaoceng" v-if="imgDefault === 2"></div>
            <img src="../../assets/2.png" />
          </div>
          <div style="margin: 0 5px" @click="imgDefault = 3">
            <div class="zhezhaoceng" v-if="imgDefault === 3"></div>
            <img src="../../assets/3.png" />
          </div>
          <div style="margin: 0 5px" @click="imgDefault = 4">
            <div class="zhezhaoceng" v-if="imgDefault === 4"></div>
            <img src="../../assets/4.png" />
          </div>
        </Col>
      </Row>
      <Row style="margin-bottom: 20px">
        <Col span="4" style="line-height: 30px">任务名称:</Col>
        <Col span="20">
          <Input
            v-model="addname"
            placeholder="Enter something..."
            style="width: 200px"
          />
        </Col>
      </Row>
      <Row style="margin-bottom: 20px">
        <Col span="4" style="line-height: 30px">任务简介:</Col>
        <Col span="20">
          <Input
            v-model="addResult"
            maxlength="200"
            show-word-limit
            type="textarea"
            placeholder="Enter something..."
            style="width: 200px"
          />
        </Col>
      </Row>
    </Modal>
  </div>
</template>

<script>
import { mapActions, mapState, mapMutations } from "vuex";
export default {
  data() {
    return {
      modelSetting: false,
      modelAdd: false,
      addname: "",
      addResult: "",
      imgDefault: 1,
      heroObject: {
        name: "",
        icon: "",
        title: "",
        categories: [],
        scores: {
          difficult: 0,
          skills: 0,
          attack: 0,
          survive: 0,
        },
        skills: [
          {
            icon: "",
            name: "",
            description: "",
            types: "",
          },
        ],
        itemsFollow: [],
        itemsAgainst: [],
        usageTips: "",
        battleTips: "",
        teamTips: "",
      },
      instance: {},
    };
  },
  computed: {
    ListAllData() {
      return this.$store.state.dataFactory.ListAllData;
    },
  },
  methods: {
    ...mapActions(["addDataCenter"]),
    // 打开设置
    settingFactory(event) {
      console.log("数据——————",event);
      // this.modelSetting = true;
      this.$router.push({
        path: "/flowChart",
        query:{
          id:event.id
        }
      });
    },
    
    handleCancel() {
      this.modelAdd = false;
    },
    handleSave() {
      this.addDataCenter({
        img: this.imgDefault,
        name: this.addname,
        synopsis: this.addResult,
        time: this.getTime(),
      }).then(() => {
        this.$Message.success("添加成功!");
        this.imgDefault = 1;
        this.addname = "";
        this.addResult = "";
        this.modelAdd = false;
      });
    },
    //添加任务
    handleAddSkills() {
      this.modelAdd = true;
    },
    getTime() {
      Date.prototype.Format = function (fmt) {
        var o = {
          "M+": this.getMonth() + 1, //月份
          "d+": this.getDate(), //日
          "H+": this.getHours(), //小时
          "m+": this.getMinutes(), //分
          "s+": this.getSeconds(), //秒
          "q+": Math.floor((this.getMonth() + 3) / 3), //季度
          S: this.getMilliseconds(), //毫秒
        };
        if (/(y+)/.test(fmt))
          fmt = fmt.replace(
            RegExp.$1,
            (this.getFullYear() + "").substr(4 - RegExp.$1.length)
          );
        for (var k in o)
          if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(
              RegExp.$1,
              RegExp.$1.length == 1
                ? o[k]
                : ("00" + o[k]).substr(("" + o[k]).length)
            );
        return fmt;
      };

      var a = new Date().Format("yyyy-MM-dd HH:mm:ss");

      return (this.nowtime = a);
    },
  },
  created() {},
  mounted() {},
};
</script>
<style lang="less">
.Model_add {
  img {
    height: 30px;
    margin-right: 16px;
    margin: 4px;
  }
  .zhezhaoceng {
    background: #2e85df80;
    height: 40px;
    width: 40px;
    position: absolute;
    border-radius: 20px;
  }
}
</style>
<style scoped lang="less">
.create {
  margin: 50px 30px 0 30px;
  .coreStyle {
    margin: 20px 0;
  }
  .btnStyle {
    margin: 20px 120px;
  }
  .addNewReport {
    margin: 10px;
    width: 350px;
    height: 192px;
    border: 1px solid #ccc;
    border-radius: 10px;
    text-align: center;
    line-height: 200px;
    float: left;
  }
  .addNewReport:hover {
    border: 1px solid #2d8cf0;
    color: #2d8cf0;
  }
  .box_content {
    border: 1px solid #ccc;
    margin: 10px 20px;
    border-radius: 10px;
    width: 350px;
    height: 192px;
    .box_top {
      display: flex;
      height: 150px;
      border-bottom: 1px solid #ccc;
      .box_top_Icon {
        padding: 0 20px;
        line-height: 150px;
        img {
          height: 50px;
        }
      }
      .box_ref_time {
        .box_name {
          font-size: 20px;
          font-weight: 800;
          padding: 20px 0;
        }
        .box_time {
          padding-top: 30px;
          font-size: 14px;
          .icons {
            cursor: pointer;
            color: #489cd7;
          }
        }
      }
    }
  }
  .box_foot {
    display: flex;
    justify-content: space-between;
    line-height: 40px;
    border-radius: 0 0 10px 10px;
    background: #f8f9fb;
    color: #a1a5a7;
    .bf_btn {
      width: 100px;
      line-height: 40px;
      text-align: center;
      cursor: pointer;
    }
    .bf_btn:hover {
      color: #2d8cf0;
    }
  }
}
</style>
